/**
 * 定义分页全局变量
 */
var page_maintain = new page({search:searchMaintain,callback:funcMaintain});

$(document).ready(function(){
	setTimeout(function(){
		searchMaintain(page_maintain);
	}, 1000);
	//$(document).on("click","#addMaintain", function(){
	//	addMaintain();
	//})
});


/**
 * 定义容器全局变量
 */
var con_maintain = new container({
	datagrid:'#maintaingrid',
	datagridtoolbar:'#maintaingrid-toolbar',
	singleSelect:true});

/**
 * 查询
 * @param page
 */
function searchMaintain(pg){
	if(pg == undefined || pg == null){
		pg = page_maintain;
	}
	var url = ctx + "/equipMaintain/query";
	page_maintain.pageSize = pg.pageSize;
	page_maintain.pageNumber = pg.pageNumber;
	query(url, getMaintainCondition(), con_maintain, page_maintain);
}

/**
 * 获取查询条件
 * @returns {condition}
 */
function getMaintainCondition(){
	var equipId=$("#maintainEquipId").val();
	var condition = {};
	
	condition.equipId = equipId;
	
	return condition;
}

/**
 * 回调函数
 */
function funcMaintain(){
	$("#maintaingrid").datagrid({onClickRow:function(index,row){
	}});
}

/**
 * 添加
 */
function addMaintain(){
	var row = null;
	row = getSelectedRow("#datagrid");
	$('#dialog').dialog({
		title: '添加',
		width: 600,
		height: 500,
		closed: false,
		cache: false,
		modal: true,
		href:ctx + "/web/data/equip_maintain/add.jsp",
		onClose:function(){
			destroy('dialog','#dialogDiv');
			maintain();
		},
		onLoad:function(){
			var equipId=row.id;
			$("#addform_equipId").val(equipId);
			$("#addform").form('load',{});
			getType('');
		},
		buttons: [{
			text:'保存',
			iconCls:'icon-ok',
			handler:function(){
				var bool = $("#addform_maintain").form('enableValidation').form('validate');
				if(!bool){
					return;
				}
				var data = $("#addform_maintain").serializeJson();

				$.ajax({
					type : "POST",
					url : ctx + "/equipMaintain/create",
					cache: false,
					data: new FormData($('#addform_maintain')[0]),
					processData: false,
					contentType: false,
					dataType:"json",
					success : function(data) {
						if(!showMsg(data,"添加成功")){
							return;
						}
						$('#dialog').dialog('close');
						searchMaintain(page_maintain);
					}
				});
			}
		},{
			text:'取消',
			iconCls:'icon-cancel',
			handler:function(){
				$('#dialog').dialog('close');
			}
		}]
	});
}

/**
 * 下载
 */
function downloadMaintain(){
	var row = null;
	row = getSelectedRow("#maintaingrid");
	if(!row){
		return;
	}
	var link = ctx + "/equipMaintain/download.json?maintainId=" + row.id;
	window.open(link);
}

function deleteMaintain(){
	var row = getSelectedRow("#maintaingrid");
	if(row){
		$.messager.confirm('提示', '确定删除?', function(r){
			if (r){
				$.ajax({
					url : ctx+"/equipMaintain/delete",
					data : {id:row.id},
					dataType : 'json',
					type : 'post',
					success : function (data) {
						if(!showMsg(data,"删除成功")){
							return;
						}
						searchMaintain(page_maintain);
					}});
			}
		});
	}
}